<template>
    <el-row>
        <el-col :span="2">
            <el-text>选择时间范围</el-text>
        </el-col>
        <el-col :span="20">
            <el-date-picker v-model="dateRange" type="datetimerange" start-placeholder="开始" end-placeholder="截至"
                format="YYYY-MM-DD HH:mm:ss" date-format="YYYY/MM/DD ddd" time-format="A hh:mm:ss" @change="getLogList"
                clearable />
                &nbsp;&nbsp;&nbsp;<el-button type="primary" @click="getLogList" plain>刷新</el-button>
        </el-col>
    </el-row>
    <el-divider></el-divider>
    <el-table :data="logList" max-height="500" style="width: 100%" :header-cell-style="{ background: '#E5EBF1' }">
        <el-table-column prop="moduleName" label="操作模块" width="160" />
        <el-table-column prop="requestDate" label="日期" width="110" sortable />
        <el-table-column prop="userName" label="操作用户" width="" />
        <el-table-column prop="userIdentity" label="操作身份" width="" sortable/>
        <el-table-column prop="methodName" label="执行方法" width="" />
                <el-table-column prop="requestIp" label="IP" width="" />
        <el-table-column prop="requestUrl" label="URL" width="" />
        <el-table-column prop="requestMethod" label="请求方式" width="" sortable/>
        
    </el-table>

    <el-pagination v-model:current-page="currentPage" v-model:page-size="pageSize" :page-sizes="[10, 20, 50, 100]"
        :small="true" :disabled="false" :background="true" layout="total, sizes, prev, pager, next, jumper"
        :total="total" @size-change="getLogList" @current-change="getLogList" />
</template>

<script setup>
import { ref } from 'vue'
import { logGetService } from '@/api/other.js'
import { ElMessage } from 'element-plus'

const logList = ref([])
const total = ref(0)
const dateRange = ref()
const currentPage = ref(1)
const pageSize = ref(10)

async function getLogList() {
    try {
        let result = null;
        if (dateRange.value == null) {
            result = await logGetService(currentPage.value, pageSize.value, ["0001-01-01T00:00", "9999-12-31T15:59:59"]);
        } else {
            result = await logGetService(currentPage.value, pageSize.value, dateRange.value);
        }
        if (result.code == 200) {
            logList.value = result.data.list;
            total.value = result.data.total;
            ElMessage.success(result.msg)
        } else if (result.code == 401) {
            router.push('/login')
            ElMessage.error(result.msg)
        } else {
            ElMessage.warning(result.msg)
        }
    } catch {
        ElMessage.error("系统异常 (GetLog)")
    }
}
getLogList()

</script>

<style></style>